﻿using System;
using System.Web.Configuration;
using eCommerce.core;
using eCommerce.core.Helpers;
using eCommerce.db;
using eCommerce.db.BORespository;

namespace eCommerce.web.Controls.Article
{
    public partial class Detail : System.Web.UI.UserControl
    {
        protected int ArticleId;
        protected string Title        = string.Empty;
        protected string Body         = string.Empty;
        protected string Source       = string.Empty;
        protected string CategoryName = string.Empty;
        protected string ParentId     = string.Empty;
        protected DateTime PublishOn  = DateTime.MinValue;
        
        protected void Page_Load(object sender, EventArgs e)
        {            
            ArticleId = Utils.GetIdFromRequestString(Utils.ArticleId, 0);

            if (ArticleId > 0)
            {
                ArticleDetail();

            }
        }

        public void ArticleDetail()
        {
            var o = ArticleBo.GetById(ArticleId);
            if (o != null)
            {
                Title        = o.Title;
                Body         = o.Body;
                Source       = o.Source;
                PublishOn    = o.PublishOn;

                //CategoryName = CategoryBo.GetCategoryName(o.//CategoryId);

                var cate = CategoryBo.GetById(o.CategoryId);
                CategoryName = cate.Name;
                

                //var imgHref = string.Format(Constant.ThumbImage, WebConfigurationManager.AppSettings["Thumbnail"], o.ImgAvatar, (int)SettingType.Article, 674);
                //ltImage.Text = string.Format("<a href=\"{0}\">{1}</a>", UrlHelper.ArticleDetail(o.CategoryUrl, o.ArticleId, o.ArticleUrl), imgHref);

                if(cate.ParentId == 19 || cate.ParentId == 25 || cate.ParentId == 30 || cate.ParentId == 36)
                {
                    liComment.Visible = false;  
                    divComment.Visible = false;
                    liCategory.Visible = false;  
                }
            }
        }
    }
}